/* Copyright(C): Leaf Johnson 2009,2010

    This file is part of leaf-lib.

    leaf-lib is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    leaf-lib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with leaf-lib.  If not, see <http://www.gnu.org/licenses/>.


 * 
 * 
 */


#ifndef KEYBOARD_H_INCLUDED
#define KEYBOARD_H_INCLUDED
#include <avr/io.h>
#include <devices_ext/ch452.h>
#include <leaf/osiface.h>

#define CH452_CONFIGED 1
#define CH452_PORT		PORTC
#define CH452_DDR		DDRC
#define CH452_DIN		PC0
#define CH452_CLK		PC1
#define CH452_LOAD		PC2
#define CH452_INPUT		_BV(CH452_DIN) | _BV(CH452_CLK) | _BV(CH452_LOAD)
#define CH452_PIN		PINE
#define CH452_DOUT_PORT	PINE
#define CH452_DOUT_DDR	DDRE
#define CH452_DOUT		PE4
#include "ch452.h"

extern MsgBox keyboardCap;
void keyboard_init( void );
static inline void keyboard_on( void )
{
	ch452_write( 0x0422 );//0b0100,0010,0010 设置工作模式 键盘扫描+键盘中断
	sbi( EIFR, INT4 );
	sbi( EIMSK, INT4 );
}
int keyboard_read( void *buf, size_t sz );
uint8_t keyboard_getc( void );
void keyboard_set_notice( pMsgBox mb );
uint8_t keyboard_byte( void );
void keyboard_set_mid( uint8_t id );
void keyboard_set_tbl( uint8_t *tbl, uint8_t sz );

void keyboard_test( void );

#include "keyboard_tbls.h"
#endif /* KEYBOARD_H_INCLUDED */
